//
//  ZMZSXiangQingViewController.m
//  ZhangMiZhuShou
//
//  Created by ryou on 2021/7/26.
//

#import "ZMZSXiangQingViewController.h"
#define kpmAcountMtitleArray @[@"图标",@"账号",@"密码",@"标记"]

@interface ZMZSXiangQingViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *zmxzsAcountMTableView;
@end

@implementation ZMZSXiangQingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"详情";

    [self.view addSubview:self.zmxzsAcountMTableView];
    
}

-(UITableView *)zmxzsAcountMTableView{
    
    if (!_zmxzsAcountMTableView) {
        _zmxzsAcountMTableView=[[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _zmxzsAcountMTableView.delegate=self;
        _zmxzsAcountMTableView.dataSource=self;
        _zmxzsAcountMTableView.backgroundColor=kZMXZSMainColor;
        _zmxzsAcountMTableView.separatorStyle=UITableViewCellSeparatorStyleNone;

    }
    return _zmxzsAcountMTableView;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    UITableViewCell *AMCell=[tableView cellForRowAtIndexPath:indexPath];
    if (!AMCell) {
        AMCell=[[UITableViewCell alloc]init];
    }
//    351 × 122 pixels
    AMCell.backgroundColor=[UIColor clearColor];

    [self createViewIndex:indexPath.row celll:AMCell];
   
    return AMCell;
}
-(void)createViewIndex:(NSInteger )index celll:(UITableViewCell *)AMCell{
    CGFloat zmxzsbgW = kZMXZSWidth - 40;
    CGFloat zmxzsbgH = zmxzsbgW * 74 / 355;
    AMCell.selectionStyle=UITableViewCellSelectionStyleNone;
    UIImageView * cellBg=[[UIImageView alloc]initWithFrame:CGRectMake(20, 10, zmxzsbgW,zmxzsbgH)];
    cellBg.image=[UIImage imageNamed:@"zmxzs_icon_cellbg.png"];
    cellBg.contentMode=UIViewContentModeScaleToFill;
    [AMCell addSubview:cellBg];
    AMCell.backgroundColor=kZMXZSMainColor;
    
    UILabel *AcountMtitle=[[UILabel alloc]initWithFrame:CGRectMake(30, 0, 100, zmxzsbgH)];
    AcountMtitle.text=kpmAcountMtitleArray[index];
    AcountMtitle.textColor=[UIColor grayColor];
    [cellBg addSubview:AcountMtitle];

    if (index == 0) {
        UIImageView *AcountMtitleAcountMcameraImageView=[[UIImageView alloc]initWithFrame:CGRectMake(zmxzsbgW - zmxzsbgH - 15, 15, zmxzsbgH -30, zmxzsbgH - 30)];
        AcountMtitleAcountMcameraImageView.image = [UIImage imageWithData:self.amDict[@"ZMZSZMZSaccountmanagermuserpmbiaojipmicon"]];
        [cellBg addSubview: AcountMtitleAcountMcameraImageView];
        AcountMtitleAcountMcameraImageView.layer.cornerRadius=10;
        AcountMtitleAcountMcameraImageView.clipsToBounds=YES;
        AcountMtitleAcountMcameraImageView.userInteractionEnabled=YES;
      }
    else
    {
        UITextField *textfield=[[UITextField alloc]initWithFrame:CGRectMake(1, 0, zmxzsbgW - 40, zmxzsbgH)];
        textfield.textAlignment = NSTextAlignmentRight;
        textfield.returnKeyType = UIReturnKeyDone;
        textfield.textColor =[UIColor grayColor];
        [cellBg addSubview:textfield];
        
     
        if (index==1) {
            textfield.text = self.amDict[@"ZMZSZMZSaccountmanagermuserdatazhanghao"];
        }
        if (index == 2) {
            textfield.text = self.amDict[@"ZMZSZMZSaccountmanagermuserdatamima"];
        }
        if (index ==3) {
            textfield.text = self.amDict[@"ZMZSZMZSaccountmanagermuserpmbiaoji"];
        }
    }
}
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return kpmAcountMtitleArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat zmxzsbgW = kZMXZSWidth - 40;
    CGFloat zmxzsbgH = zmxzsbgW * 74 / 355;

    return zmxzsbgH + 20;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    CGFloat zmxzsbgW = kZMXZSWidth - 40;
    CGFloat zmxzsbgH = zmxzsbgW * 74 / 355;

    UIView *foodview=[[UIView alloc]init];
    
    UIButton *AcountMAcountMsavebtn=[[UIButton alloc]initWithFrame:CGRectMake(kZMXZSWidth / 2 - 70, (zmxzsbgH + 20 )/2 - 30, 140, 60)];
    [AcountMAcountMsavebtn setBackgroundImage:[UIImage imageNamed:@"zmxzs_icon_cellbg.png"] forState:UIControlStateNormal];
    [foodview addSubview:AcountMAcountMsavebtn];
    AcountMAcountMsavebtn.layer.cornerRadius = 30;
    AcountMAcountMsavebtn.clipsToBounds=YES;
    [AcountMAcountMsavebtn setTitle:@"分享" forState:UIControlStateNormal];
    [AcountMAcountMsavebtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [AcountMAcountMsavebtn addTarget:self action:@selector(AcountMAcountMsavebtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    return foodview;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    CGFloat zmxzsbgW = kZMXZSWidth - 40;
    CGFloat zmxzsbgH = zmxzsbgW * 74 / 355;
    return zmxzsbgH + 20;
}
-(void)AcountMAcountMsavebtnClick{
    [self share];
}
-(void)share{
    NSString *textToShare1 = @"账号分享";
    UIImage *imageToShare = [self screenSnapshot:self.view];
    NSArray *activityItems = @[textToShare1, imageToShare];
    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];

    //成功失败的回调block
        UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError) {

            if (completed){
                NSLog(@"completed");
            }else{
                NSLog(@"canceled");
            }
       };
    activityVC.completionWithItemsHandler = myBlock;
    [self presentViewController:activityVC animated:YES completion:nil];
}
- (UIImage*)screenSnapshot:(UIView *)view{
    UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImage * iii = [[UIImage alloc] initWithData: UIImageJPEGRepresentation(image, 0.8)];
    return iii;
}

@end
